unit wbDebug;

interface
uses
	Windows, Classes, Controls;

function GetLastErrorText: string;
function GetParentStr(AControl: TControl): string;
function GetOwnerStr(AComponent: TComponent): string;

implementation

function GetLastErrorText: string;
var
	lz: Cardinal;
	err: array[0..512] of Char;
begin
	lz := GetLastError;
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, lz, 0, @err, 512, nil);
	Result:= string(err);
end;


function GetParentStr(AControl: TControl): string;
begin
  Result := AControl.Name;
  while Assigned(AControl.Parent) do begin
    if AControl.Parent.Name = '' then
      Result := '<' + AControl.Parent.ClassName + '>.' + Result
    else
      Result := AControl.Parent.Name + '.' + Result;
    AControl := AControl.Parent;
  end;
end;

function GetOwnerStr(AComponent: TComponent): string;
begin
  Result := AComponent.Name;
  while Assigned(AComponent.Owner) do begin
    if AComponent.Owner.Name = '' then
      Result := '<' + AComponent.Owner.ClassName + '>.' + Result
    else
      Result := AComponent.Owner.Name + '.' + Result;
    AComponent := AComponent.Owner;
  end;
end;

end.
